Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix e.File() being picky with relative paths after 4.7.0 introduced echo.Fs support #2123

Merged
merged 4 commits into from Mar 13, 2022

Conversation

aldas
Copy link
Contributor

@aldas aldas commented Mar 12, 2022

Fix e.File() being picky with relative paths after 4.7.0 introduced echo.Fs support (Go 1.16+).

See #2117 (comment)

TLDR: fs.Fs and to be specific os.DirFs.Open does not like path to files starting with ./, ../ and / but os.Open did not care about that and now old code has problems.

func main() {
	e := echo.New()
	e.Use(middleware.Logger())
	e.Use(middleware.Recover())

	e.File("", "./index.html")

	e.Logger.Fatal(e.Start(":8080"))
}
./
./main.go
./index.html

@codecov
Copy link

codecov bot commented Mar 12, 2022

Codecov Report

Merging #2123 (8b9b584) into master (5ebed44) will decrease coverage by 0.10%.
The diff coverage is 66.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2123      +/-   ##
==========================================
- Coverage   92.21%   92.10%   -0.11%     
==========================================
  Files          37       37              
  Lines        3018     3028      +10     
==========================================
+ Hits         2783     2789       +6     
- Misses        148      150       +2     
- Partials       87       89       +2     
Impacted Files Coverage Δ
echo_fs_go1.16.go 89.65% <66.66%> (-6.18%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5ebed44...8b9b584. Read the comment docs.

@aldas
Copy link
Contributor Author

aldas commented Mar 12, 2022

Absolute paths have similar problem with echo.defaultFs.Open method

All these cases must work:

func main() {
	e := echo.New()
	e.Use(middleware.Logger())
	e.Use(middleware.Recover())

	e.Static("/static1", "./") // curl http://localhost:8080/static1/main.go
	dir, _ := os.Getwd()
	e.Static("/static2", dir+"/") // curl http://localhost:8080/static2/main.go

	e.File("/f1", "./main.go")    // curl http://localhost:8080/f1
	e.File("/f2", dir+"/main.go") // curl http://localhost:8080/f2

	e.GET("/a1", func(c echo.Context) error { // curl http://localhost:8080/a1
		return c.Attachment("./main.go", "test")
	})
	e.GET("/a2", func(c echo.Context) error { // curl http://localhost:8080/a2
		return c.Attachment(dir+"/main.go", "test")
	})

	e.Logger.Fatal(e.Start(":8080"))
}

@aldas aldas merged commit 3f5b733 into labstack:master Mar 13, 2022
@aldas aldas deleted the echo_file_relativepath branch July 12, 2022 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant